package com.lianyu.wangyiyun.widget.musiceffect.view;

import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;

import com.lianyu.wangyiyun.widget.musiceffect.drawable.AncientEffectDrawable;
import com.lianyu.wangyiyun.widget.musiceffect.drawable.BaseEffectDrawable;

/**
 * @author Chen Yuguang
 */
public class EffectView extends androidx.appcompat.widget.AppCompatImageView {

    private int mPaintColor = Color.parseColor("#CABFA3");

    public EffectView(Context context) {
        super(context);
        init();
    }

    public EffectView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public EffectView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init() {
        setAncientEffectDrawable();
    }

    private BaseEffectDrawable mDrawable;

    private void initDrawable(BaseEffectDrawable drawable) {
        mDrawable = drawable;
        setImageDrawable(mDrawable);
        setColor();
    }

    public void setAncientEffectDrawable() {
        initDrawable(new AncientEffectDrawable(getContext()));
    }

    public void setColor() {
        if (mDrawable != null) {
            mDrawable.setColor(mPaintColor);
        }
    }

    public void setColor(int color) {
        mPaintColor = color;
        if (mDrawable != null) {
            mDrawable.setColor(color);
        }
    }


    public void onCall(final byte[] data) {
        if (mDrawable != null) {
            mDrawable.onCall(data);
        }
    }

    public void onWaveCall(byte[] data) {
        if (mDrawable != null) {
            mDrawable.onWaveCall(data);
        }
    }
}
